#include <iostream>
#include <vector> 
using namespace std;

class Book; 
class CD;

class LibraryVisitor {
	public:
		virtual void visit(Book *)=0;
		virtual void visit(CD *)=0;
};

class LibraryItemInterface{
	public:
		virtual void Access(LibraryVisitor *)=0;
		virtual void Do()=0;
}; 

class Book:public LibraryItemInterface{
	public:
		void Access(LibraryVisitor * pl){
			pl->visit(this);
		}
		void Do(){
			cout<<"Book.Do~"<<endl;
		}
};

class CD:public LibraryItemInterface{
	public:
		void Access(LibraryVisitor * pl){
			pl->visit(this);
		}
		void Do(){
			cout<<"CD.Do~"<<endl;
		}
};

class Manager{
	private:
		vector <LibraryItemInterface *> v;
	public:
		void Add(LibraryItemInterface *t){
			v.push_back(t);
		}
		void Request(LibraryVisitor *pL){
			vector <LibraryItemInterface *>::iterator it=v.begin();
			for (;it!=v.end();it++){
				(*it)->Access(pL);
			}
		}
};

class LSPN:public LibraryVisitor {
	public:
		void visit (Book *t){
			t->Do();
		}
		void visit (CD *t){
			t->Do();
		}
};


int main(void){
	Manager *pM=new Manager();
	LibraryItemInterface *p1=new Book();
	LibraryItemInterface *p2=new CD();
	LibraryItemInterface *p3=new CD();
	LibraryVisitor *pL=new LSPN();
	pM->Add(p1);
	pM->Add(p2);
	pM->Add(p3);
	pM->Request(pL);
	
	delete pM;
	delete p1;
	delete p2;
	delete p3;
	delete pL;
	return 0;
}
